/**
 * DriverSupport.java created by zhangzhidong 
 * at 下午12:51:00 2017年5月26日
 */
package cn.edu.bjtu.workbench.driver;

import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

import cn.edu.bjtu.workbench.api.CGNetworkDesigner;
import cn.edu.bjtu.workbench.api.MLNetworkDesigner;
import cn.edu.bjtu.workbench.configuration.TextCategorizationCNNConfig;
import cn.edu.bjtu.workbench.core.Deep4jModelType;
import cn.edu.bjtu.workbench.core.LoggerSupport;
/**
 * @author zhangzhidong<br>
 * comment generated at 2017年5月26日下午12:51:00<br>
 * 
 */
public abstract class DriverSupport extends LoggerSupport{
	TextCategorizationCNNConfig config = null;
	public DriverSupport() {
		 config = TextCategorizationCNNConfig.get();
	}
	final public void run(CommandLine cli) throws Exception{
		//do other works before run;
		//FIXME 这么判断可能有问题,因为实现了CNNNetworkDesignHandler它,后面两个返回的都是true
		//为了安全还是在子类重写方法的时候重新调用config.setCNN_TYPE;
		if(this instanceof CGNetworkDesigner){
			config.setCNN_TYPE(Deep4jModelType.ComputationGraph);
		}else if(this instanceof MLNetworkDesigner){
			config.setCNN_TYPE(Deep4jModelType.MultiLayerNetwork);
		}
		runInternal(cli);
		
	}
	public abstract void runInternal(CommandLine cli) throws Exception;
	protected Options getOptions(){
		Options options = new Options();  
		  options.addOption("h", "help", false, "Print this usage information");  
		  options.addOption("v", "verbose", false, "Print out VERBOSE information" );  
		  options.addOption("f", "file", true, "File to save program output to");  
		  return options;
	}
	public CommandLine parese(String args[]) throws ParseException{
		CommandLineParser clp = new BasicParser( );
		return clp.parse(getOptions(), args);
	}
	
	
	public void invoke(String args[]) throws Exception{
		run(parese(args));
	}
	
}
